<template>
  <view @click="btnChooseAdd">
    <!-- 选中地址部分 -->
    <view class="choose-address" v-if="JSON.stringify(address) === '{}'">
      <button type="primary" size="mini" @click="btnChooseAdd">请选择收货地址</button>
    </view>
    <!-- 地址详细信息 -->
    <view class="add-detail" v-else>
      <view class="row1">
        <view class="row1-l">
          <view class="username">
            收货人：{{ address.userName }}
          </view>
        </view>
        <view class="row1-r">
          <view class="phone">
            电话：{{ address.telNumber }}
          </view>
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view>
      </view>
      <view class="row2">
        <view class="row2-l">
          收货地址：
        </view>
        <view class="row2-r">
          {{ addr }}
        </view>
      </view>
    </view>


    <!-- 底部边框 -->
    <image src="/static/cart_border@2x.png" class="border-bom"></image>
  </view>
</template>

<script>
  import { mapState, mapMutations, mapGetters } from 'vuex'
  export default {
    name: "my-address",
    data() {
      return {
        
      };
    },
    computed: {
      ...mapState('user', ['address']),
      ...mapGetters('user', ['addr'])
      
    },
    methods: {
      ...mapMutations('user', ['updataAddress']),
      async btnChooseAdd() {
        const [ err, succ] = await uni.chooseAddress().catch(err => err)
      if (err === null && succ.errMsg === 'chooseAddress:ok') {
            // 为 data 里面的收货地址对象赋值
            // this.address = succ
            this.updataAddress(succ)
          }
    }
  }
  }
</script>

<style lang="scss">
  .choose-address {
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .border-bom {
    display: block;
    width: 100%;
    height: 5px;
  }

  .add-detail {
    padding: 0 5px;
    font-size: 12px;
    height: 90px;
    display: flex;
    flex-direction: column;
    justify-content: center;

    .row1 {
      display: flex;
      justify-content: space-between;

      .row1-r {
        display: flex;
        justify-content: space-between;
      }
    }

    .row2 {
      margin-top: 10px;
      display: flex;
      // justify-content: space-between;
      align-items: center;

      .row2-l {
        white-space: nowrap;
      }
    }
  }
</style>
